package com.freak.neteasecloudmusic.modules.video;

import com.freak.httphelper.ApiCallback;
import com.freak.httphelper.HttpMethods;
import com.freak.httphelper.RxPresenter;
import com.freak.httphelper.SubscriberCallBack;
import com.freak.neteasecloudmusic.app.api.ApiService;
import com.freak.neteasecloudmusic.commom.constants.Constants;
import com.freak.neteasecloudmusic.modules.video.entity.VideoTagEntity;
import com.freak.neteasecloudmusic.utils.ToastUtil;

import io.reactivex.Observable;

/**
 * @author freak
 * @date 2019/2/19
 */

public class VideoPresenter extends RxPresenter<VideoContract.View> implements VideoContract.Presenter {
    private ApiService mApiService = HttpMethods.getInstance().create(ApiService.class);

    @Override
    public void getVideoTag() {
        Observable<VideoTagEntity> observable = mApiService.getVideoTag();
        addSubscription(observable, new SubscriberCallBack<>(new ApiCallback<VideoTagEntity>() {
            @Override
            public void onSuccess(VideoTagEntity model) {
                if (model.getCode() == Constants.SUCCESS_CODE) {
                    mView.getVideoTagSuccess(model);
                } else {
                    ToastUtil.shortShow("获取视频标签失败");
                }
            }

            @Override
            public void onFailure(String msg) {
                mView.showToast(msg);
            }
        }));
    }

}
